import * as auth from '../../utils/auth'

export default {
  state: {
    // user: auth.getToken(),
    // userInfo: {},
    count: 2,
    collapse: false,
    menuRouteLoaded: false, // 菜单和路由是否已经加载
    navTree: [], // 导航菜单树
    keepAliveList: '',
    mainTabsActiveName: '', // 当前标签页名
    // local: auth.localRead('local'), //语言
    language: [],
    dialogVisible: false // 弹出框显示状态
  },
  getters: {
    collapse(state) { // 对应着上面state
      return state.collapse
    }
  },
  mutations: {
    delTabs(state) {
      state.mainTabs = [{
        name: '首页',
        title: '首页',
        code: 'home',
        icon: 'el-icon-s-home',
        close: false
      }]
      auth.delTabs()
    },
    onCollapse(state) { // 改变收缩状态
      state.collapse = !state.collapse
    },
    updateMainTabs(state, tabs) { // 更新tabs栏数据
      state.mainTabs = tabs
      auth.setTabs(tabs)
    },
    updateMainTabsActiveName(state, name) { // 更新当前选中tabs栏名称
      state.mainTabsActiveName = name
    },
    setLocal(state, lang) { // 更新语言
      auth.localSave('local', lang)
      state.local = lang
    },
    setLang(state, lang) {
      state.language.push(lang)
      auth.setLang(lang)
    },
    setNavTree(state, navTree) { // 设置导航菜单树
      state.navTree = navTree;
    },
    menuRouteLoaded(state, menuRouteLoaded) { // 改变菜单和路由的加载状态
      state.menuRouteLoaded = menuRouteLoaded;
    },
    setDialog(state, boolean) { // 设置弹出框状态
      state.dialogVisible = boolean
    },
    setKeepAliveList(state, keepAliveList) {
      state.keepAliveList = keepAliveList;
    }
  },
  actions: {}
}
